import { createSlice } from "@reduxjs/toolkit";
import { setCookie, getCookie } from "@/utils/cookie";

export const Token = createSlice({
  name: 'token',
  initialState: {
    value: getCookie('token') || ''
  },
  reducers: {
    saveToken: (state, action) => {
      setCookie('token', action.payload)
      state.value = action.payload
    }
  }
})

export const { saveToken } = Token.actions
export default Token.reducer
